package com.site_assembly.apiImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.service.WasteApiService;
import com.service.form.WasteForm;
import com.site_assembly.common.GetIdUtil;
import com.util.Result;
import com.zsd.apiService.WasteApi;
import io.netty.handler.codec.http.HttpRequest;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@Slf4j
@Api(tags = "子站点端（废品管理）接口", description = "提供子站点端（废品管理）相关的 Rest API")
public class WasteApiImpl implements WasteApiService {


    @Resource
    private WasteApi wasteApi;

    @Resource
    private GetIdUtil getIdUtil;


    @Override
    @ApiOperation("分页查询子站点所有废品信息")
    public Result findAllWasteMessageByPageAndSiteId(@ApiParam(name = "current", value = "当前页", example = "1") Integer current,
                                                     @ApiParam(name = "pageSize", value = "页容量", example = "1") Integer pageSize) {
        log.info("当前页{},页容量{}", current, pageSize);

        Integer siteId = getIdUtil.getId();
        log.info("子站点Id{}", siteId);

        Result messages = wasteApi.findAllWasteMessageByPageAndSiteId(siteId, current, pageSize);

        return messages;
    }

    @Override
    @ApiOperation("添加子站点废品信息")
    @ApiResponses({@ApiResponse(code = 20000, message = "添加成功"), @ApiResponse(code = 40000, message = "添加失败")})
    public Result addWasteMessageBySiteId(WasteForm wasteForm) {

        log.info("废品信息{}", wasteForm);

        Integer siteId = getIdUtil.getId();
        com.zsd.apiService.form.WasteForm form = new com.zsd.apiService.form.WasteForm();
        form.setSiteId(siteId);
        BeanUtils.copyProperties(wasteForm, form);
        wasteApi.addWasteMessageBySiteId(form);

        return Result.success();
    }

    @Override
    @ApiOperation("子站点废品单价修改")
    @ApiResponses({@ApiResponse(code = 20000, message = "修改成功"), @ApiResponse(code = 40000, message = "修改失败")})
    public Result setWasteOfPriceByWasteTypeAndSiteId(WasteForm wasteForm) {

        log.info("废品修改信息{}", wasteForm);
        Integer siteId = getIdUtil.getId();
        com.zsd.apiService.form.WasteForm form = new com.zsd.apiService.form.WasteForm();
        form.setSiteId(siteId);
        BeanUtils.copyProperties(wasteForm, form);
        wasteApi.setWasteOfPriceByWasteTypeAndSiteId(form);
        return Result.success();
    }
}
